<?php
class Comment_mdl extends CI_Model
{
	public static $m_arrTpl = array('info'=>'0',
									'news'=>'1',
									'cul'=>'2',
									'strategy'=>'3',
									'nous'=>'4',
									'ask'=>'5');
	function __construct()
	{
		parent::__construct();
	}
	
	public function getCommentById($p_begin = 0,$p_page = 10,$p_type = 0,$p_id = 0,$model = 0)
	{
		if ($p_begin == null)
		{
			$p_begin = 0;
		}
		
		
		if ($p_type == 0)
		{
			$strSql = "select count(id) as icount from dili_u_m_comment where comment_id = $p_id and comment_type=$model";
			$arr = $this->db->query($strSql)->result_array();
			if (empty($arr))
			{
				return 0;
			}
			return $arr[0]['icount'];
		}
		else 
		{
			$strSql = "select comment_user,comment_content,update_time,comment_anonymity from dili_u_m_comment where comment_id = $p_id and comment_type=$model order by id desc limit $p_begin,$p_page";
			$arrRet =  $this->db->query($strSql)->result_array();
			return $arrRet;
		}
	}
	
	public function setCommentById($p_id,$p_user,$p_content,$p_anon,$p_type,$title)
	{
		// 0=资讯|1=新闻|2=文化|3=攻略|4=常识|5=问答
		$time = time();
		//$date = date('Y-m-d H:i:s',time()+8*3600); 
		$strSql = "INSERT INTO dili_u_m_comment(create_time,
									  update_time,
									  comment_user,
									  comment_type,
									  comment_content,
									  comment_anonymity,
									  comment_id,
									  comment_title
									  ) 
							  VALUES( $time,$time,'$p_user',$p_type,'$p_content',$p_anon,$p_id,'$title')";
		
		return $this->db->query($strSql);
	}
	
	
}